import { reactive, ref } from 'vue';
import { defineStore } from 'pinia';

/**
 * 系统选项 缓存状态管理
 */
export const SysOptions = defineStore('SysOptions', () => {
  let globalOptions = reactive([]) as any;
  let rptGroupOptions = reactive([]) as any;
  let instrOptions = reactive([]) as any;
  let localOptions = reactive([]) as any;

  /**
   * 设置全局系统参数
   * @param arr
   */
  function setGlobalOptions(arr: any) {
    if (arr && arr.length === 0) {
      globalOptions.length = 0;
    } else {
      Object.assign(globalOptions, arr);
    }
  }

  /**
   * 设置报告单元系统参数
   * @param arr
   */
  function setRptGroupOptions(arr: any) {
    if (arr && arr.length === 0) {
      rptGroupOptions.length = 0;
    } else {
      Object.assign(rptGroupOptions, arr);
    }
  }

  /**
   * 设置仪器系统参数
   * @param arr
   */
  function setInstrOptions(arr: any) {
    if (arr && arr.length === 0) {
      instrOptions.length = 0;
    } else {
      Object.assign(instrOptions, arr);
    }
  }

  /**
   * 设置本地系统参数
   * @param arr
   */
  function setLocalOptions(arr: any) {
    if (arr && arr.length === 0) {
      localOptions.length = 0;
    } else {
      Object.assign(localOptions, arr);
    }
  }

  return {
    globalOptions,
    rptGroupOptions,
    instrOptions,
    localOptions,
    setGlobalOptions,
    setRptGroupOptions,
    setInstrOptions,
    setLocalOptions
  };
});
